{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "176f1266",
   "metadata": {},
   "outputs": [],
   "source": [
    "*日期 2022-10-12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81a6ccf9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1, 有序的数字结构-字符串\n",
    ">> 1,字符串的基本概念\n",
    "单引号：'allows embedded \"double\" quotes'\n",
    "\n",
    "双引号：\"allows embedded 'single' quotes\"\n",
    "\n",
    "三重引用： ，'''Three single quotes'''\"\"\"Three double quotes\"\"\"\n",
    "\n",
    "三重引号字符串可能跨越多行 - 所有关联的空格都将包含在字符串文本中。\n",
    "\n",
    "作为单个表达式的一部分且它们之间只有空格的字符串文本将隐式转换为单个字符串文本。那是。(\"spam \" \"eggs\") == \"spam eggs\"\n",
    ">> 2.字符串的性质\n",
    " > 1.字符串的有序性\n",
    " > 2.字符串是有长度的\n",
    ">>1. 使用len()检查字符串的长度\n",
    " \n",
    "字符串的基础方法（运算法则）\n",
    "  1.字符串的取值：str[index]\n",
    "  2.字符串的切片：str[start,stop] stop取不到\n",
    "  3.字符串的拼接：+\n",
    "  4. in 检查成员是否存在\n",
    "字符串的一般方法(function/methods  函数/方法)\n",
    "> 1. isdigit()\n",
    "\n",
    "> 2. 有序的数字结构-列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d2698c4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72028d0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ae8f04a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"广州南方学院团委\"\n",
    "3 * text.count(\"广州\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "219f2cb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3e7b84b",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(19)\n",
    "print(\"19\")\n",
    "pirnt(age_1,type(age_1))\n",
    "print(age_2,type(age_2))\n",
    "# 如果字符串是数值 可以用int函数去转换\n",
    "if age_2.isdigit():\n",
    "    print(age_1+ int(age_2))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9983dd0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#. 有序的数字结构-列表\n",
    "* 1.列表的概念和基本性质\n",
    "    A. Python knows a number of compound data types, used to group together other values.\n",
    "    The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets.\n",
    "    Lists might contain items of different types, but usually the items all have the same type.\n",
    " \n",
    "### 2,1 列表的性质\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意： 字符串是对字符进行操作，列表是对 items元素进行操作\n",
    "\n",
    "2.列表的一般方法（如何学习）\n",
    ">1.增加\n",
    ">2.删除\n",
    ">3.改\n",
    ">4.查 ：in\n",
    "*使用.tab键查看列表的方法\n",
    "使用help（查看方法的使用规则）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "18d7a78d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "physics\n",
      "[2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "list1 = [\"physics\", \"chemistry\", 1997, 2000]\n",
    "list2 = [1, 2, 3, 4, 5, 6, 7 ]\n",
    "print(list1[0])\n",
    "print(list2[1:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2d809620",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['physics', 'chemistry', 1997, 2000]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1 = [\"physics\", \"chemistry\", 1997, 2000]\n",
    "list1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "364b5cc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1.append 增加元素到列表的末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6193bef4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(list1.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6f092cc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课后作业\n",
    "列表的方法尝试所有的方法\n",
    "总结心得（表格形式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "3efb7a7d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3723565027.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [37]\u001b[1;36m\u001b[0m\n\u001b[1;33m    |  列表的方法  | Description  || 使用方法  | 备注  |\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 作业：\n",
    "|  列表的方法  | Description  || 使用方法  | 备注  |\n",
    "|  ----  | ----  ||  ----  | ----  |\n",
    "| append |在列表末尾添加新的对象||list.append(obj)  | 只在末尾增加 因为列表是有序的 |\n",
    "| clear  |clear（） 内置实例的方法从列表中删除所有项目 ||list.clear()  |清除所有元素，相当于del. |\n",
    "| copy | copy() 函数用于复制列表 || list.copy()  | 复制一个一样的列表 |\n",
    "| count  | count() 方法用于统计某个元素在列表中出现的次数。 || list.count()  | 查询元素总共出现的次数|\n",
    "| extend | extend() 函数用于在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）。 || list.extend() | 一般是增加一个列表拓展 |\n",
    "| index  | index() 函数用于从列表中找出某个值第一个匹配项的索引位置。|| list.index()  | 用来查找元素所对应的位置 |\n",
    "| insert  | insert() 函数用于将指定对象插入列表的指定位置。 || list.insert(index,obj)  | 可以插入指定索引值的地方 |\n",
    "| pop  | pop() 函数用于移除列表中的一个元素（默认最后一个元素），并且返回该元素的值。 || list.pop() | 默认为最后一个，也可以指定 |\n",
    "| remove  |remove() 函数用于移除列表中某个值的第一个匹配项。 ||list.remove(obj) | 删除某个值的第一个 |\n",
    "| reverse  |reverse() 函数用于反向列表中元素。 || list.remove()  | 对列表的元素进行反向排序。 |\n",
    "| sort  | 单元格 || 单元格  | 单元格 |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c0ba87d",
   "metadata": {},
   "outputs": [],
   "source": [
    "### clear\n",
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']\n",
    "list1.clear()\n",
    "print (\"列表清空后 : \", list1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "893504ef",
   "metadata": {},
   "source": [
    "### copy\n",
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']\n",
    "list2 = list1.copy()\n",
    "print (\"list2 列表: \", list2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5a4a4503",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123 元素个数 :  2\n",
      "Runoob 元素个数 :  1\n"
     ]
    }
   ],
   "source": [
    "### count\n",
    "aList = [123, 'Google', 'Runoob', 'Taobao', 123];\n",
    "\n",
    "print (\"123 元素个数 : \", aList.count(123))\n",
    "print (\"Runoob 元素个数 : \", aList.count('Runoob'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "861b6f90",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "扩展后的列表： ['Google', 'Runoob', 'Taobao', 0, 1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "### extend\n",
    "list1 = ['Google', 'Runoob', 'Taobao']\n",
    "list2=list(range(5)) # 创建 0-4 的列表\n",
    "list1.extend(list2)  # 扩展列表\n",
    "print (\"扩展后的列表：\", list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "121a224d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "### index\n",
    "list1 = ['Google', 'Runoob', 'Taobao']\n",
    "print(list1.index('Runoob'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "49bf1216",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "列表插入元素后为 :  ['Google', 'Baidu', 'Runoob', 'Taobao']\n"
     ]
    }
   ],
   "source": [
    "### insert\n",
    "list1 = ['Google', 'Runoob', 'Taobao']\n",
    "list1.insert(1, 'Baidu')\n",
    "print ('列表插入元素后为 : ', list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "6ac27a98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "列表现在为 :  ['Google', 'Runoob']\n",
      "列表现在为 :  ['Google']\n"
     ]
    }
   ],
   "source": [
    "### pop\n",
    "list1 = ['Google', 'Runoob', 'Taobao']\n",
    "list1.pop()\n",
    "print (\"列表现在为 : \", list1)\n",
    "list1.pop(1)\n",
    "print (\"列表现在为 : \", list1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "75d45588",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "列表现在为 :  ['Google', 'Runoob', 'Baidu']\n",
      "列表现在为 :  ['Google', 'Runoob']\n"
     ]
    }
   ],
   "source": [
    "### remove\n",
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']\n",
    "list1.remove('Taobao')\n",
    "print (\"列表现在为 : \", list1)\n",
    "list1.remove('Baidu')\n",
    "print (\"列表现在为 : \", list1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47517319",
   "metadata": {},
   "outputs": [],
   "source": [
    "### reverse\n",
    "list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']\n",
    "list1.reverse()\n",
    "print (\"列表反转后: \", list1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
